<%@page contentType="text/html;charset=UTF-8" %>
<%@page pageEncoding="UTF-8" %>
<%@ page session="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title><spring:message code="html.title"/></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="<c:url value="/static/styles/style.css" />" type="text/css"/>

    <script type="text/javascript">
        function show_confirm(licenseName) {
            return confirm("<spring:message code="msg.licenses.delete"/>" + " " + licenseName + "?");
        }
    </script>
</head>
<body>
<div id="locationPage">
    <%-- Menu --%>
    <c:import url="../include/menu.jsp">
        <c:param name="page" value="licenses"/>
    </c:import>

    <%-- Locations list --%>
    <h2><spring:message code="header.licences.view"/></h2>
    <table class="datatable" border="1">
        <tr>
            <th style="width:5%">#</th>
            <th style="width:50%"><spring:message code="table.licenses.name"/></th>
            <th style="width: 30%"><spring:message code="table.licenses.actions"/></th>
        </tr>
        <c:forEach items="${licenses}" var="item">
            <tr>
                <td>${item.id}</td>
                <td>${item.licenseName}</td>
                <td>
                    <sec:authorize ifAnyGranted="ROLE_ADMIN">
                        <a href="<c:url value='/licenses/deleteLicense?id=${item.id}'/>"
                           onClick="return show_confirm('${item.licenseName}');">
                            <spring:message code="actions.licenses.delete"/></a>
                    </sec:authorize>
                </td>
            </tr>
        </c:forEach>
    </table>
    <c:import url="../include/pager.jsp"/>
    <h2></h2>

    <c:if test="${param.deleteError=='true'}">
        <div class="deletionError">
            <spring:message code="msg.license.deleteError"/>
        </div>
    </c:if>
    <sec:authorize ifAnyGranted="ROLE_ADMIN">
        <p><input type="button" value="<spring:message code="action.licenses.add"/>"
                  onclick="document.location.href='<c:url value="/licenses/add"/>'">
        </p>
    </sec:authorize>
</div>
</body>
</html>